{% if 'waijiao-webserver' in group_names %}
<source>
  type tail
  path /var/log/nginx/waijiao_access.log
  pos_file /var/log/td-agent/task-access.log.pos
  tag waijiao.access
  format /^\[(?<time>[^\]]*)\] (?<host>(?!admin)[^ ]*91waijiao\.com) (?<remote_addr>(?!124\.193\.177\.194|223\.72\.244\.154|124\.193\.172\.66)[^ ]*) "(?<request_uri>[^\"]+?(\?ss=(?<source>[^\&\"]*)[^\"]*)?)" (?<status>200|304) "(?<bytes_sent>[^\"]*)" "(?<request_time>[^\"]*)" "(?<upstream_response_time>[^\"]*)" "(?<http_user_agent>((?!aliyun|bot|crawl|slurp|search|lycos|robozilla|DNSPod|Wget)[^\"]){25,})" "(?<http_referer>[^\"]*)" "(?<http_x_forwarded_for>(?!124\.193\.177\.194|223\.72\.244\.154|124\.193\.172\.66)[^\"]*)" "(?<uid>[^\"]*)" "(uid=)?(?<hex_uid>[^\"]*)"$/
  time_format %d/%b/%Y:%H:%M:%S %z
</source>

<source>
  type forward
  port 24224
  bind 0.0.0.0
</source>

<match qqwry.typed.waijiao.access.reformer>
  type copy

  <store>
    type mongo
    database roi
    collection waijiao_access_log

    host 10.160.13.77
    port 27017

    flush_interval 1s
  </store>

  <store>
    type statsd

    host graphite.91peilian.com
    port 8125

    flush_interval 1s
  </store>

  <store>
    type elasticsearch

    host es.91peilian.com
    port 9200

    index_name waijiao
    type_name waijiao
  </store>
</match>

<match typed.waijiao.access.reformer>
  type qqwry
  tag qqwry.${tag}
  flush_interval 1s

  qqwry_lookup_key remote_addr
  #qqwry_lookup_key http_x_forwarded_for

  #qqwry_database /var/lib/qqwry.dat

  <record>
    area            ${area['remote_addr']}
    country         ${country['remote_addr']}
  </record>
</match>

<match waijiao.access.reformer>
  type typecast
  item_types bytes_sent:integer,status:integer,request_time:float,upstream_response_time:float,statsd_timing:float
  prefix typed
</match>

<match waijiao.access>
  type record_reformer
  output_tag ${tag}.reformer
  uid ${require "base64";if uid == '-' then Base64.encode64(hex_uid.scan(/......../).map { |x| [x.hex].pack("L").unpack("N")[0].to_s(16).rjust(8,'0').scan(/../).map{|y| y.hex.chr}.join }.join).strip else uid end}
  date ${time.strftime('%Y-%m-%d')}
  hour ${time.strftime('%H')}
  minute ${time.strftime('%M')}
  fromhost ${require 'socket';Socket.gethostname}
  timestamp ${time.strftime('%Y-%m-%dT%H:%M:%S.%L%z')}
  statsd_key ${"waijiao"+(request_uri and request_uri.gsub(/((\/[^\/]+){2}).*/, '\1').gsub(/([^\?]*)\?.*/,'\1').gsub(/[0-9]+/, "NN").gsub(/\//, ".") or '.business')}
  statsd_timing ${request_time}
  statsd_type ${"timing"}
</match>
{% endif %}

{% if 'tizi-webserver' in group_names %}
<source>
  type tail
  path /var/log/nginx/tizi_access.log
  pos_file /var/log/td-agent/task-access.log.pos
  tag tizi.access
  format /^\[(?<time>[^\]]*)\] (?<host>(?!admin)[^ ]*tizi\.com) (?<remote_addr>(?!124\.193\.177\.194|223\.72\.244\.154|124\.193\.172\.66)[^ ]*) "(?<request_uri>[^\"]+?(\?ss=(?<source>[^\&\"]*)[^\"]*)?)" (?<status>200|304) "(?<bytes_sent>[^\"]*)" "(?<request_time>[^\"]*)" "(?<upstream_response_time>[^\"]*)" "(?<http_user_agent>((?!aliyun|bot|crawl|slurp|search|lycos|robozilla|DNSPod|Wget)[^\"]){25,})" "(?<http_referer>[^\"]*)" "(?<http_x_forwarded_for>(?!124\.193\.177\.194|223\.72\.244\.154|124\.193\.172\.66)[^\"]*)" "(?<uid>[^\"]*)" "(uid=)?(?<hex_uid>[^\"]*)" "(?<TZID>[^\"]*)"/
  time_format %d/%b/%Y:%H:%M:%S %z
</source>

<source>
  type tail
  path /var/log/nginx/tizi_uc_access.log
  pos_file /var/log/td-agent/task-access_uc.log.pos
  tag tizi.access
  format /^\[(?<time>[^\]]*)\] (?<host>(?!admin)[^ ]*tizi\.com) (?<remote_addr>(?!124\.193\.177\.194|223\.72\.244\.154|124\.193\.172\.66)[^ ]*) "(?<request_uri>[^\"]+?(\?ss=(?<source>[^\&\"]*)[^\"]*)?)" (?<status>200|304) "(?<bytes_sent>[^\"]*)" "(?<request_time>[^\"]*)" "(?<upstream_response_time>[^\"]*)" "(?<http_user_agent>((?!aliyun|bot|crawl|slurp|search|lycos|robozilla|DNSPod|Wget)[^\"]){25,})" "(?<http_referer>[^\"]*)" "(?<http_x_forwarded_for>(?!124\.193\.177\.194|223\.72\.244\.154|124\.193\.172\.66)[^\"]*)" "(?<uid>[^\"]*)" "(uid=)?(?<hex_uid>[^\"]*)" "(?<TZID>[^\"]*)"/
  time_format %d/%b/%Y:%H:%M:%S %z
</source>

<source>
  type tail
  path /var/log/nginx/tizi_xue_access.log
  pos_file /var/log/td-agent/task-access_xue.log.pos
  tag tizi.access
  format /^\[(?<time>[^\]]*)\] (?<host>(?!admin)[^ ]*tizi\.com) (?<remote_addr>(?!124\.193\.177\.194|223\.72\.244\.154|124\.193\.172\.66)[^ ]*) "(?<request_uri>[^\"]+?(\?ss=(?<source>[^\&\"]*)[^\"]*)?)" (?<status>200|304) "(?<bytes_sent>[^\"]*)" "(?<request_time>[^\"]*)" "(?<upstream_response_time>[^\"]*)" "(?<http_user_agent>((?!aliyun|bot|crawl|slurp|search|lycos|robozilla|DNSPod|Wget)[^\"]){25,})" "(?<http_referer>[^\"]*)" "(?<http_x_forwarded_for>(?!124\.193\.177\.194|223\.72\.244\.154|124\.193\.172\.66)[^\"]*)" "(?<uid>[^\"]*)" "(uid=)?(?<hex_uid>[^\"]*)" "(?<TZID>[^\"]*)"/
  time_format %d/%b/%Y:%H:%M:%S %z
</source>

<source>
  type forward
  port 24224
  bind 0.0.0.0
</source>

<match qqwry.typed.tizi.access.reformer>
  type copy

  <store>
    type mongo

    database tizi_roi
    collection tizi_access_log

    host 10.160.13.77
    port 27017

    flush_interval 1s
  </store>

  <store>
    type statsd

    host graphite.91peilian.com
    port 8125

    flush_interval 1s
  </store>

  <store>
    type elasticsearch

    host es.91peilian.com
    port 9200

    index_name tizi
    type_name tizi
  </store>
</match>

<match typed.tizi.access.reformer>
  type qqwry
  tag qqwry.${tag}
  flush_interval 1s

  #qqwry_lookup_key remote_addr
  qqwry_lookup_key http_x_forwarded_for

  #qqwry_database /var/lib/qqwry.dat

  <record>
    area            ${area['http_x_forwarded_for']}
    country         ${country['http_x_forwarded_for']}
  </record>
</match>

<match tizi.access.reformer>
  type typecast
  item_types bytes_sent:integer,status:integer,request_time:float,upstream_response_time:float,statsd_timing:float
  prefix typed
</match>

<match tizi.access>
  type record_reformer
  output_tag ${tag}.reformer
  uid ${require "base64";if uid == '-' then Base64.encode64(hex_uid.scan(/......../).map { |x| [x.hex].pack("L").unpack("N")[0].to_s(16).rjust(8,'0').scan(/../).map{|y| y.hex.chr}.join }.join).strip else uid end}
  pathname ${request_uri.split('?')[0]}
  src ${require "cgi"; qs = request_uri.split('?')[1]; qs and CGI::parse(qs)['src'][0]}
  date ${time.strftime('%Y-%m-%d')}
  hour ${time.strftime('%H')}
  minute ${time.strftime('%M')}
  timestamp ${time.strftime('%Y-%m-%dT%H:%M:%S.%L%z')}
  fromhost ${require 'socket';Socket.gethostname}
  statsd_key ${"tizi"+(request_uri and request_uri.gsub(/((\/[^\/]+){2}).*/, '\1').gsub(/([^\?]*)\?.*/,'\1').gsub(/[0-9]+/, "NN").gsub(/\//, ".") or ".buziness");}
  statsd_timing ${request_time}
  statsd_type ${"timing"}
</match>
{% endif %}
